#pragma once
#include <string>

namespace umtl
{
	namespace invmat
	{
		class mat_t
		{
		public:
			typedef float elem_type;

			elem_type a, b, c, d, end;

			mat_t() : a(0), b(0), c(0), d(0), end(0) {}

			inline mat_t& operator!()	{
				elem_type discriminant = a*d - b*c;

				if( discriminant != 0 )
				{
					elem_type t = a;
					a = d;
					d = t;

					b = -b;
					c = -c;

					*this *= (1/discriminant);
				}

				return *this;
			}

			inline mat_t & operator*=(elem_type v)	{
				a *= v;	b *= v;	c *= v;	d *= v;
				return *this;
			}

			std::wstring str()
			{
				wchar_t s[5];

				s[0] = (wchar_t)floor(a+0.5f);
				s[1] = (wchar_t)floor(b+0.5f);
				s[2] = (wchar_t)floor(c+0.5f);
				s[3] = (wchar_t)floor(d+0.5f);
				s[4] = 0;

				return s;
			}
		};

		std::wstring encoding( std::wstring str );
		std::wstring decoding( std::wstring str );
	}
}